package com.example.demo;

import cn.hutool.crypto.digest.MD5;
import com.example.demo.config.AbilityOperation;
import com.example.demo.utils.SecurityUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class DemoTestApplication {

    @Autowired
    private AbilityOperation abilityOperation;

    @Test
    public void contextLoads() throws UnsupportedEncodingException {
        try {
            String decodeValue = SecurityUtils.decodeAES256HexUpper("0B788EA2C967146769518C5955575ED4", SecurityUtils.decodeHexUpper(abilityOperation.getAccessToken()));
            System.out.println(decodeValue);
        } catch (IllegalBlockSizeException | InvalidKeyException | BadPaddingException | NoSuchAlgorithmException |
                 NoSuchPaddingException e) {
            throw new RuntimeException(e);
        }
    }

    @Test
    public void test() {
        String account = "admin";
        String code = "ZenTaoSSO1";
        String key = "e8emm7nscg2w006qldw8elkh6td0rk13";
        long time = System.currentTimeMillis();
        String token = MD5.create().digestHex(code + key + time);
        String url = "http://10.254.197.110:8088/api.php?m=user&f=apilogin&account=" + account + "&code=" + code + "&time=" + time + "&token=" + token;
        System.out.println(url);
    }
}
